<template>
  <div class="amend_charge_item">

    <el-row>
      <el-col :span="24"><div class="title-add-item">修改收费项目</div></el-col>
    </el-row>

    <el-form
      class="amend_item_form"
      :rules="rules"
      ref="form"
      :model="form"
      label-width="200px"
      :label-position="labelPosition">
      <el-form-item label="项目名称：" prop="name">
        <el-input v-model="form.name" style="width: 220px;"></el-input>
      </el-form-item>
      <el-form-item label="请选择项目类型：" prop="region">
        <el-select v-model="form.region" placeholder="请选择项目类型" style="width: 220px;">
          <el-option label="请选择项目类型" value=""></el-option>
          <el-option label="项目类型1" value="shanghai"></el-option>
          <el-option label="项目类型2" value="beijing"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目起始时间：" prop="beginDate">
        <el-date-picker type="date" placeholder="请选择开始日期" v-model="form.beginDate" style="width: 220px;"></el-date-picker>
      </el-form-item>
      <el-form-item label="项目结束时间：" prop="endDate">
        <el-date-picker type="date" placeholder="请选择结束日期" v-model="form.endDate" style="width: 220px;"></el-date-picker>
      </el-form-item>
      <el-form-item label="项目描述：" prop="desc">
        <el-input type="textarea" v-model="form.desc" style="width: 220px;"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"  @click="submitForm('form')">保存</el-button>
        <el-button class="btn-item-cancel"  @click="resetForm('form')">取消</el-button>
      </el-form-item>
    </el-form>


  </div>
</template>

<script>

  export default {
    data(){
      return{
        labelPosition:'left',
        form: {
          name: '',
          region: '',
          beginDate: '',
          endDate: '',
          desc: ''
        },
        rules: {
          name: [
            { required: true, message: '请输入项目名称', trigger: 'blur' },
            { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          region: [
            { required: true, message: '请选择项目类型', trigger: 'change' }
          ],
          beginDate: [
            { type: 'date', required: true, message: '请选择开始日期', trigger: 'change' }
          ],
          endDate: [
            { type: 'date', required: true, message: '请选择结束日期', trigger: 'change' }
          ],
          desc: [
            { required: true, message: '请填写项目描述', trigger: 'blur' }
          ]
        }
      }
    },
    methods:{
      submitForm(formName) {
//        this.$refs[formName].validate((valid) => {
        this.$refs[formName].validate(
          function(valid) {
            if (valid) {
              alert('submit!');
            } else {
//            console.log('error submit!!');
              return false;
            }
          });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style>
  .amend_charge_item .title-add-item{
    height: 60px;
    line-height: 60px;
    font-size: 18px;
    padding-left: 30px;
    margin-bottom: 10px;
    color: #333333;
    background: #ffffff;
  }
  .amend_charge_item .amend_item_form{
    background: #ffffff;
    padding: 50px 0 50px 30px;
  }
  .amend_charge_item .amend_item_form label.el-form-item__label{
    font-size: 16px;
    color: #666666;
  }
  .amend_charge_item .amend_item_form .el-form-item{
    margin-bottom: 50px;
  }
  .amend_charge_item .amend_item_form .btn-item-cancel{
    margin-left: 100px;
  }
</style>
